package com.xywy.fwc.net;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xywy.fwc.bean.FwcHomeData;
import com.xywy.fwc.bean.FwcItem;

public class MenuParser extends BaseParser<List<FwcItem>> {

	@Override
	public List<FwcItem> parseJson(String result) {
	   List<FwcItem> list = new ArrayList<FwcItem>();
		try {
			JSONArray json = new JSONArray(result);
			for(int i=0;i<json.length();i++){
				FwcItem item = new FwcItem();
				JSONObject temp = (JSONObject) json.get(i);
				item.setTitle(temp.optString("title"));
				item.setUrl(temp.optString("url"));
				List<FwcItem> subList = new ArrayList<FwcItem>();
				if(temp.has("content")){
					JSONArray array = temp.optJSONArray("content");
					for(int j=0;j<array.length();j++){
						JSONObject jitem = (JSONObject) array.get(j);
						FwcItem subItem = new FwcItem();
						subItem.setTitle(jitem.optString("title"));
						subItem.setUrl(jitem.optString("url"));
						subList.add(subItem);
					}
				}
				item.setFwcItem(subList);
				System.out.println("++++++++++++++++");
				list.add(item);
			}
			System.out.println(list.size());
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

}
